home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-16 | 38.2 KB | 1,227 lines | [TEXT/PJMM] |
- program AboutDemo; { Last Update : 6/15/91 }
- {}
- { This program demonstrates the About… 2.0 Unit. }
- {}
- { About… is copyrighted, and I reserve all rights to it; both source and }
- { compiled versions. Please do not distribute modified copies without my }
- { permission, or remove this notice. Thanks. }
- {}
- { About is being distributed as $10 shareware. Reigstered users receive a}
- { diskette containing the Think Pascal source for the current version of}
- { About… and may use it and future versions in any program or programs}
- { you write. You need not credit me for its use.}
- {}
- { Jon Wind (About…)}
- { 2374 Hillwood Drive}
- { Maplewood, MN 55119}
- {}
-
-
- { Modal procedure: }
- { this routine does everything, returning to calling proc only after the window is dismissed... }
- {• procedure BuildAbout (WinRect: Rect;}
- { WinProc, TEXTid: Integer;}
- { WinTitle, WinMsg: Str255;}
- { WinMisc: AboutRec);}
-
-
- { Modeless procedures: }
- { returns true if the specified window is an About window; otherwise returns false }
- {• function IsAboutWindow (theWindow: WindowPtr): Boolean;}
-
- { open About window and return pointer to it - returns NIL if window is not created }
- { Note: you should keep track of this pointer only if you wish to keep specific track of it }
- {• function OpenAbout (WinRect: Rect;}
- { WinProc, TEXTid: Integer;}
- { WinTitle, WinMsg: Str255;}
- { WinMisc: AboutRec): WindowPtr;}
-
- { handle event relating to About window, ie updateEvt, activateEvt, mouseDown, keyDown, etc… }
- { Note: this proc should be called after every event for each About window for everything to work correctly }
- { Note: this proc calls the CloseAbout proc if the OK button is selected }
- { Note: you can filter events passed to it to simulate a modal dialog }
- {• procedure HandleAbout (var theWindow: WindowPtr;}
- { var theEvent: EventRecord);}
-
- { close the specified About window, kill data structures associated with it, and set theWindow to NIL… }
- { Note: this proc is called by the HandleAbout proc when an About window is dismissed by selecting its OK button }
- { Note: this proc should be called when the program needs to remove an About window }
- {• procedure CloseAbout (var theWindow: WindowPtr);}
-
-
- uses
- About; { …my unit! }
-
-
- const
- maxDemoWindows = 12;
-
- SharewareMsg = 'About… is $5 SHAREWARE.';
- CopyrightMsg = '© 1989-91 by Jon Wind, All rights reserved';
-
- AboutDemoID = 128;
- HelpTEXTID = 128;
- AboutTEXTID = 1000;
- IconID = 1000;
- On = 1;
- Off = 0;
- Disable = 255;
- goNext = 1;
- goPrev = -1;
-
- { *** The constants below were added to be used in the case statements.}
- enterKey = 3;
- BS = 8;
- tabKey = 9;
- CR = 13;
- leftArrow = 28;
- rightArrow = 29;
- upArrow = 30;
- downArrow = 31;
- num0 = 48;
- num1 = 49;
- num2 = 50;
- num3 = 51;
- num4 = 52;
- num5 = 53;
- num6 = 54;
- num7 = 55;
- num8 = 56;
- num9 = 57;
- upperC = 67;
- upperV = 86;
- upperX = 88;
- lowerC = 99;
- lowerV = 118;
- lowerX = 120;
-
- dTopEd = 5;
- dLeftEd = 7;
- dRightEd = 9;
- dBottomEd = 11;
- dSetRectBtn = 12;
-
- dBoxWRad = 13;
- dPlainWRad = 14;
- dAltWRad = 15;
- dNoGrowRad = 16;
- dRDocWRad = 17;
-
- dTitleEd = 24;
- dMsgChk = 25;
- dMsgEd = 26;
-
- dCenterRad = 27;
- dTopWinRad = 28;
- dMainMonRad = 29;
-
- dIconChk = 30;
- dStylChk = 31;
- dCopyChk = 32;
- dCloseChk = 33;
- dEquivChk = 34;
- dModalChk = 35;
-
- dAboutBtn = 36;
-
- type
- AuxWinPtr = ^AuxWinRec;
- AuxWinHandle = ^AuxWinPtr;
- AuxWinRec = record
- awNext: AuxWinHandle; {handle to next AuxWinRec}
- awOwner: WindowPtr; {ptr to window }
- awCTable: CTabHandle; {color table for this window}
- dialogCItem: Handle; {handle to dialog manager structures}
- awFlags: LONGINT; {reserved for expansion}
- awReserved: CTabHandle; {reserved for expansion}
- awRefCon: LONGINT; {user Constant}
- end;
- DemoVars = record
- WinRect: Rect;
- BoxType, WinProc, Center: Integer;
- Msg, ShowIcon, Style, CopyIt, Close, Keys, Modal: Boolean;
- MsgText, TitleText: Str255;
- end;
-
- var
- AboutStuff: AboutRec;
- CrossCurs: CursHandle; { cross cursor handle }
- MainDlgPtr: DialogPtr; { main dialog box pointer }
- DemoWinPtr: array[1..maxDemoWindows] of WindowPtr;
- zVar: DemoVars;
- ramRect: Rect;
- Finished: Boolean;
- lastClick, ramDemand, ramFree: longint;
-
-
-
- function aNum2Str (aNum: LongInt): Str255;
- { NumToString procedure available as a function }
- var
- NumStr: Str255;
- begin
- NumToString(aNum, NumStr);
- aNum2Str := NumStr;
- end; { of func aNum2Str }
-
-
- function aStr2Num (NumStr: Str255): Integer;
- { StringToNum procedure available as a function }
- { Note: won't accurately return numbers if > 32767 or if letters are in NumStr }
- var
- aNum: LongInt;
- begin
- StringToNum(Copy(NumStr, 1, 5), aNum);
- if aNum < maxInt then
- aStr2Num := aNum
- else
- aStr2Num := maxInt;
- end; { of func aStr2Num }
-
-
- function CtrlEnabled (theDialog: DialogPtr;
- whichItem: Integer): Boolean;
- var
- thetype: Integer;
- itmHdl: Handle;
- itmrect: Rect;
- begin
- GetDItem(theDialog, whichItem, theType, itmHdl, itmrect);{ get button junk }
- CtrlEnabled := (ControlHandle(itmHdl)^^.contrlHilite <> Disable);
- end; { of proc CtrlEnabled }
-
-
- procedure DrawDefaultBtn (theDialog: DialogPtr;
- Item: Integer);
- { outline default button in any dialog window }
- var
- theInt: Integer;
- btnHdl: Handle;
- thePen: PenState;
- btnrect: Rect;
- begin
- SetPort(theDialog); { set window to current graf port }
- GetPenState(thePen); { save current pen }
- if (theDialog <> FrontWindow) | (not CtrlEnabled(theDialog, DialogPeek(theDialog)^.aDefItem)) then
- PenPat(gray);
- GetDItem(theDialog, DialogPeek(theDialog)^.aDefItem, theInt, btnHdl, btnrect); { get item location }
- Pensize(3, 3); { no wimpy button outlines here }
- InsetRect(btnrect, -4, -4); { set rectangle around button }
- FrameRoundRect(btnrect, 16, 16); { draw the sucker! }
- SetPenState(thePen); { restore old pen }
- end; { of proc DrawDefaultBtn }
-
-
-
- function GetAuxWin (theWindow: WindowPtr;
- var awHndl: AuxWinHandle): BOOLEAN;
- inline
- $AA42;
-
-
- procedure FixWindowColor (theWindow: DialogPtr);
- { set window background color to match custom colored window content fill }
- var
- usedDefaultColors: Boolean;
- theWorld: SysEnvRec;
- RGBbackground: RGBColor;
- awHndl: AuxWinHandle;
- savePort: GrafPtr;
- begin
- if (SysEnvirons(1, theWorld) <> envNotPresent) then { SysEnvirons call is available }
- if theWorld.hasColorQD then { has Color QuickDraw - OK to look for window color record… }
- begin
- GetPort(savePort);
- usedDefaultColors := GetAuxWin(theWindow, awHndl);
- RGBbackground := awHndl^^.awCTable^^.ctTable[cFrameColor].rgb;
- RGBBackColor(RGBbackground); { set background to match wContentColor when drawing }
- SetPort(theWindow);
- EraseRect(theWindow^.portRect);
- SetPort(savePort);
- end;
- end; { of proc FixWindowColor }
-
-
- procedure CenterWindow (theDialog: DialogPtr;
- defaultbtn: Boolean);
- { Center window - center higher for large screens - show, set port }
- var
- usedDefaultColors: Boolean;
- theWorld: SysEnvRec;
- RGBbackground: RGBColor;
- awHndl: AuxWinHandle;
- begin
- SetPort(theDialog); { set window to current graf port }
- with screenBits, theDialog^ do
- MoveWindow(theDialog, ((bounds.right - bounds.left - portrect.right + portrect.left) div 2), ((bounds.bottom - bounds.top - portrect.bottom + portrect.top + 20) div 3), True);
-
- ShowWindow(theDialog);
- FixWindowColor(theDialog);
-
- if defaultbtn then
- DrawDefaultBtn(theDialog, 0);
- end; { of proc CenterWindow }
-
-
- procedure FakeClick (theDialog: DialogPtr;
- theButton: Integer);
- { select/deselect a button in a dialog }
- var
- theInt: Integer;
- LInt: LongInt;
- btnHdl: Handle;
- btnrect: Rect;
- begin
- GetDItem(theDialog, theButton, theInt, btnHdl, btnrect);
- HiliteControl(ControlHandle(btnHdl), 1);
- Delay(8, LInt);
- HiliteControl(ControlHandle(btnHdl), 0);
- end; { of proc FakeClick }
-
-
- procedure SetBtnTitle (theDialog: DialogPtr;
- Btn: Integer;
- Title: Str255);
- { update button title for dialog }
- var
- itmNum: Integer;
- itmRect: Rect;
- CurTitle: Str255;
- itmHdl: Handle;
- begin
- GetDItem(theDialog, Btn, itmNum, itmHdl, itmRect); { get button junk }
- GetCTitle(ControlHandle(itmHdl), CurTitle); { get current title }
- if Title <> CurTitle then
- SetCTitle(ControlHandle(itmHdl), Title); { set title }
- end; { of proc SetBtnTitle }
-
-
- procedure GetSetBtn (theDialog: DialogPtr;
- Btn, BtnState: Integer);
- { update button status for dialog }
- var
- itmNum: Integer;
- itmrect: Rect;
- itmHdl: Handle;
- begin
- GetDItem(theDialog, Btn, itmNum, itmHdl, itmrect); { get button junk }
- if BtnState <> Disable then
- begin
- HiliteControl(ControlHandle(itmHdl), Off); { enable control }
- SetCtlValue(ControlHandle(itmHdl), BtnState) { set button state }
- end
- else
- HiliteControl(ControlHandle(itmHdl), BtnState); { disable control }
- end; { of proc GetSetBtn }
-
-
- function GetEdText (theDialog: DialogPtr;
- Which: Integer): Str255;
- { return edit text contents }
- var
- itmNum: Integer;
- itmrect: Rect;
- itmHdl: Handle;
- Msg: Str255;
- begin
- GetDItem(theDialog, Which, itmNum, itmHdl, itmrect);
- GetIText(itmHdl, Msg);
- GetEdText := Msg;
- end; { of func GetEdText }
-
-
- procedure ChangeChoiceText (theDialog: DialogPtr;
- Which: Integer;
- Msg: Str255);
- { change edit text contents }
- var
- itmNum: Integer;
- itmrect: Rect;
- itmHdl: Handle;
- begin
- if GetEdText(theDialog, Which) <> Msg then { check current text before updating... }
- begin
- GetDItem(theDialog, Which, itmNum, itmHdl, itmrect);
- SetIText(itmHdl, Msg); { ...to avoid flicker }
- end;
- end; { of proc ChangeChoiceText }
-
-
- procedure DoHelp;
- { Display modal help dialog - not a lot of code needed... }
- var
- HelpWinRect: Rect;
- SavePort: GrafPtr;
- begin
- GetPort(SavePort); { save current port }
- SetPort(MainDlgPtr);
- EraseRect(ramRect); { memory count won't be accurate during modal display, so lose it }
- InvalRect(ramRect);
- with AboutStuff do { set up the text stuff to be used by the About... unit }
- begin
- FontInfo[AboutMsg].Font := Geneva; { use Geneva for Message }
- FontInfo[AboutMsg].Size := 9; { use 9 point for Message }
- FontInfo[AboutMsg].Face := [outline]; { use outline face for Message }
- FontInfo[AboutMsg].Color := GreenColor; { use green for Message }
- FontInfo[AboutTEXT].Font := Monaco; { use Monaco for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Size := 9; { use 9 point for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Face := [bold]; { use bold face for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Color := RedColor; { use red for TEXT - 'styl' resource may override }
- TEXTCopy := True; { allow copy to clipboard }
- KeyEquivs := True; { allow key equivalents }
- CloseBox := False; { set close box boolean }
- Styled := True; { set use of styled text (if possible) }
- CenterMode := AboutMainCenter; { center window }
- MainIcon := 1000; { use icon }
- ClickIcon := AboutNoIcon; { no new icon when original is clicked on - use MainIcon if only new message is desired }
- ClickMsg := ''; { no click message - no need to define if ClickIcon = AboutNoIcon }
- end;
- SetRect(HelpWinRect, 0, 0, 420, 257);
- BuildAbout(HelpWinRect, dBoxProc, HelpTEXTID, '', CopyrightMsg, AboutStuff);
- SetPort(SavePort); { save current port }
- end;
-
-
- function TabSelectText (theDialog: DialogPtr;
- direction: Integer): Boolean;
- { select the next, previous, or only edit text field }
- { returns true if a field was found and selected }
- var
- thePtr: ^Integer;
- x, theItem, totItems, itmtype: Integer;
- itmHdl: Handle;
- itmrect: Rect;
- begin
- TabSelectText := False;
- theItem := 0;
- x := Succ(DialogPeek(theDialog)^.editField); { current edit text item }
- if x = 0 then
- Exit(TabSelectText); { no edit text fields in dialog! }
- thePtr := Pointer(DialogPeek(theDialog)^.Items^);
- totItems := 1 + thePtr^; { total # of items in dialog }
- while theItem = 0 do
- begin
- x := x + direction;
- if x > totItems then
- x := 1; { reset index to first item }
- if x < 1 then
- x := totItems; { reset index to last item }
- GetDItem(theDialog, x, itmtype, itmHdl, itmrect); { get item's rect }
- if (itmtype = editText) or (itmtype = editText + itemDisable) then
- theItem := x; { found an edit text item }
- end;
- SelIText(theDialog, theItem, 0, maxint); { select ALL edit text }
- TabSelectText := True;
- end; { of func TabSelectText }
-
-
- procedure PutRectVarInDialog;
- { put current values into edit text boxes and set buttons }
- begin
- ChangeChoiceText(MainDlgPtr, dTopEd, aNum2Str(zVar.WinRect.top));
- ChangeChoiceText(MainDlgPtr, dLeftEd, aNum2Str(zVar.WinRect.left));
- ChangeChoiceText(MainDlgPtr, dRightEd, aNum2Str(zVar.WinRect.right));
- ChangeChoiceText(MainDlgPtr, dBottomEd, aNum2Str(zVar.WinRect.bottom));
- end; { of proc PutRectVarInDialog }
-
-
- procedure FixCloseCheckbox;
- begin
- if (zVar.BoxType <> dNoGrowRad) & (zVar.BoxType <> dRDocWRad) then
- begin
- GetSetBtn(MainDlgPtr, dCloseChk, Off); { uncheck checkbox - no need to change zClose var though... }
- GetSetBtn(MainDlgPtr, dCloseChk, Disable); { disable checkbox }
- end
- else
- GetSetBtn(MainDlgPtr, dCloseChk, Ord(zVar.Close)); { restore checkbox to actual value }
- end;{of proc FixCloseCheckbox }
-
-
- procedure PutVarsInDialog;
- { put current values into edit text boxes and set buttons }
- begin
- GetSetBtn(MainDlgPtr, dMsgChk, Ord(zVar.Msg)); { set use message text checkbox }
- GetSetBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, On); { set Center Window radio }
- GetSetBtn(MainDlgPtr, dIconChk, Ord(zVar.ShowIcon)); { set Show Icon checkbox }
- GetSetBtn(MainDlgPtr, dStylChk, Ord(zVar.Style)); { set use styled text checkbox }
- GetSetBtn(MainDlgPtr, dCopyChk, Ord(zVar.CopyIt)); { set copy to clipboard checkbox }
- GetSetBtn(MainDlgPtr, dCloseChk, Ord(zVar.Close)); { set close box checkbox }
- GetSetBtn(MainDlgPtr, dEquivChk, Ord(zVar.Keys)); { set key equivalents checkbox }
- PutRectVarInDialog;
- ChangeChoiceText(MainDlgPtr, dTitleEd, zVar.TitleText);
- ChangeChoiceText(MainDlgPtr, dMsgEd, zVar.MsgText);
- SelItext(MainDlgPtr, dTopEd, 0, maxint);
- GetSetBtn(MainDlgPtr, zVar.BoxType, On); { set window type radio btn }
- end; { of proc PutVarsInDialog }
-
-
- procedure DrawFreeRam;
- var
- SavePort: GrafPtr;
- fontStuff: FontInfo;
- ramStr: Str255;
- begin
- GetPort(SavePort); { save current port }
- SetPort(MainDlgPtr);
- ramFree := FreeMem;
- NumToString(ramFree, ramStr);
- EraseRect(ramRect);
- TextSize(9);
- TextFont(Geneva);
- GetFontInfo(fontStuff);
- MoveTo(ramrect.left, ramRect.bottom - fontStuff.descent);
- DrawString(Concat(ramStr, ' bytes free'));
- TextSize(12);
- TextFont(0);
- SetPort(SavePort); { restore old port }
- end; { of proc DrawFreeRam }
-
-
- function GetNextWinHdl: Integer;
- var
- j: SignedByte;
- begin
- GetNextWinHdl := 0;
- for j := 1 to maxDemoWindows do
- if DemoWinPtr[j] = nil then
- begin
- GetNextWinHdl := j;
- leave;
- end;
- end; { of func GetNextWinHdl }
-
-
- procedure DemoAbout;
- var
- aWin: SignedByte;
- begin
- case zVar.BoxType of
- dBoxWRad:
- zVar.WinProc := dBoxProc;
- dPlainWRad:
- zVar.WinProc := plainDBox;
- dAltWRad:
- zVar.WinProc := altDBoxProc;
- dNoGrowRad:
- zVar.WinProc := noGrowDocProc;
- dRDocWRad:
- zVar.WinProc := rDocProc;
- end;
- with AboutStuff do { set up the text stuff to be used by the About... unit }
- begin
- FontInfo[AboutMsg].Font := 0; { use Chicago for Message }
- FontInfo[AboutMsg].Size := 0; { use 12 point for Message }
- FontInfo[AboutMsg].Face := []; { use normal face for Message }
- FontInfo[AboutMsg].Color := BlueColor; { use blue for Message }
- FontInfo[AboutTEXT].Font := Geneva; { use Geneva for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Size := 9; { use 9 point for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Face := []; { use normal face for TEXT - 'styl' resource may override }
- FontInfo[AboutTEXT].Color := GreenColor; { use green for TEXT - 'styl' resource may override }
- TEXTCopy := zVar.CopyIt; { set copy to clipboard boolean }
- KeyEquivs := zVar.Keys; { set key equivalents boolean }
- CloseBox := zVar.Close; { set close box boolean }
- Styled := zVar.Style; { set use of styled text (if possible) }
- CenterMode := zVar.Center; { set center window integer }
- if zVar.ShowIcon then
- MainIcon := IconID
- else { Note: use contant "AboutNoIcon" to indicate no icon }
- MainIcon := AboutNoIcon;
- ClickIcon := IconID + 1;
- ClickMsg := SharewareMsg;
- end;
- zVar.WinRect.top := aStr2Num(GetEdText(MainDlgPtr, dTopEd));
- zVar.WinRect.left := aStr2Num(GetEdText(MainDlgPtr, dLeftEd));
- zVar.WinRect.right := aStr2Num(GetEdText(MainDlgPtr, dRightEd));
- zVar.WinRect.bottom := aStr2Num(GetEdText(MainDlgPtr, dBottomEd));
- zVar.TitleText := GetEdText(MainDlgPtr, dTitleEd);
- zVar.MsgText := GetEdText(MainDlgPtr, dMsgEd);
-
- PutRectVarInDialog; { stuff rect values back into text fields }
- SelItext(MainDlgPtr, Succ(DialogPeek(MainDlgPtr)^.editField), 0, 0); { deselect text }
-
- { find first available window pointer in array }
- aWin := GetNextWinHdl;
- if aWin > 0 then
- begin
- if zVar.Msg then
- begin
- if zVar.Modal then
- begin
- BuildAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, zVar.MsgText, AboutStuff);
- Exit(DemoAbout);
- end
- else
- DemoWinPtr[aWin] := OpenAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, zVar.MsgText, AboutStuff)
- end
- else
- begin
- if zVar.Modal then
- begin
- BuildAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, '', AboutStuff);
- Exit(DemoAbout);
- end
- else
- DemoWinPtr[aWin] := OpenAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, '', AboutStuff);
- end;
-
- if DemoWinPtr[aWin] <> nil then { window was built }
- begin
- DrawFreeRam;
-
- { Disable OK button if there are no more window handles free }
- if GetNextWinHdl = 0 then
- begin
- GetSetBtn(MainDlgPtr, OK, Disable); { disable OK button since all handles are in use }
- DrawDefaultBtn(MainDlgPtr, OK);
- end;
- end
- else
- SysBeep(3); { window was not built }
- end;
- end; { of proc DemoAbout }
-
-
- procedure DealwithKeyDowns (var Event: EventRecord);
- var
- j: SignedByte;
- theWindow, origWindow: WindowPtr;
- theKey, FieldInUse, whichItem: Integer;
- TEPeek: DialogPeek;
- CmdKeyUsd: Boolean;
- err: OSErr;
- begin
- theWindow := FrontWindow;
-
- if IsAboutWindow(theWindow) then
- begin
- origWindow := theWindow; { save original window pointer }
- HandleAbout(theWindow, Event);
- if theWindow = nil then { About window was killed }
- for j := 1 to maxDemoWindows do { remove entry window pointer array }
- if DemoWinPtr[j] = origWindow then
- begin
- DemoWinPtr[j] := nil;
- GetSetBtn(MainDlgPtr, OK, Off); { enable OK button since at least one handle is not in use }
- DrawDefaultBtn(MainDlgPtr, OK);
- end;
- end
- else if (GetWRefCon(theWindow) = AboutDemoID) then
- begin
- whichItem := 0;
- TEPeek := DialogPeek(theWindow);
- FieldInUse := TEPeek^.editField + 1; { get # of edit field in use }
- theKey := BitAnd(Event.message, charCodeMask); { decode char }
- CmdKeyUsd := (BitAnd(Event.modifiers, cmdKey) <> 0); { cmd key down? }
- if (FieldInUse <> dMsgEd) and (theKey = CR) then { allow CRs in msg text field }
- theKey := enterKey;
- case theKey of
- enterKey: { OK Button equivalents }
- begin
- whichItem := -1; { hides key }
- if CtrlEnabled(theWindow, OK) then
- begin
- FakeClick(theWindow, OK);
- DemoAbout;
- end;
- end;
- lowerC, upperC: { not needed with System 7.0! }
- if CmdKeyUsd then
- begin { copy selection to clipboard }
- DlgCopy(theWindow);
- if TEGetScrapLen > 0 then
- if ZeroScrap = noErr then
- Err := TEtoScrap;
- whichItem := -1; { hides key }
- end
- else if FieldInUse <= dBottomEd then
- whichItem := -1; { hides non-numeric keys }
- lowerV, upperV: { not needed with System 7.0! }
- if CmdKeyUsd then
- begin { paste clipboard }
- Err := TEfromScrap;
- if TEGetScrapLen > 0 then
- DlgPaste(theWindow);
- whichItem := -1; { hides key }
- end
- else if FieldInUse <= dBottomEd then
- whichItem := -1; { hides non-numeric keys }
- lowerX, upperX: { not needed with System 7.0! }
- if CmdKeyUsd then
- begin { cut selection to clipboard }
- DlgCut(theWindow);
- if TEGetScrapLen > 0 then
- if ZeroScrap = noErr then
- Err := TEtoScrap;
- whichItem := -1; { hides key }
- end
- else if FieldInUse <= dBottomEd then
- whichItem := -1; { hides non-numeric keys }
- downArrow:
- if TabSelectText(theWindow, goNext) then
- whichItem := -1; { hides key }
- upArrow:
- if TabSelectText(theWindow, goPrev) then
- whichItem := -1; { hides key }
- tabKey:
- if BitAnd(Event.modifiers, shiftKey) <> 0 then { shift key down }
- if TabSelectText(theWindow, goPrev) then
- whichItem := -1; { hides key }
- otherwise
- if FieldInUse <= dBottomEd then
- if not (theKey in [num0..num9, BS, leftArrow, rightArrow]) then
- whichItem := -1; { hides non-numeric keys }
- end;
- if whichItem < 0 then
- Event.what := 0; { 'EAT' processed cmd key }
- end;
-
- end; { of proc DealwithKeyDowns }
-
-
- function GetGrayRgn: RgnHandle;
- { get gray region }
- var
- thePtr: ^RgnHandle;
- begin
- thePtr := Pointer($9EE);
- GetGrayRgn := thePtr^;
- end; { of func GetGrayRgn }
-
-
- procedure rotateByte (p: Ptr);
- inline
- $205F, $1010, $E218, $1080;
- { move.l (sp)+,a0}
- { move.b (a0),d0}
- { ror.b #1,d0}
- { move.b d0,(a0)}
-
-
- function ShiftDown: Boolean;
- var
- keys: keymap;
- begin
- GetKeys(keys);
- if bittst(@keys, 63) then
- shiftdown := True
- else
- shiftdown := False;
- end;
-
-
- procedure HandleSetRect (theDialog: DialogPtr);
- { deal with set rect for sample window }
- var
- j, itmType, winKind, totItems, height, width: Integer;
- startPt, endPt: Point;
- oldRect, titleRect: Rect;
- deskPort: GrafPtr;
- mouseEvent: EventRecord;
- itmHdl: Handle;
- rgnHdl: RgnHandle;
- IntPtr: ^Integer;
- marqueePat: Pattern;
- lastDraw: LongInt;
- theString: Str255;
- begin
- SelItext(theDialog, Succ(DialogPeek(theDialog)^.editField), 0, 0); { deselect text }
-
- IntPtr := Pointer(DialogPeek(theDialog)^.Items^);
- totItems := Succ(IntPtr^); { total # of items in dialog }
-
- PenPat(gray);
- PenMode(patBic); { to gray existing text... }
- PaintRect(theDialog^.portRect); { "gray out" text }
- PenNormal;
-
- SetBtnTitle(theDialog, dSetRectBtn, 'Click'); { change btn title to help user & force btn redraw }
- for j := 1 to 4 do { redraw rect coordinates so they're not gray }
- begin
- GetDItem(theDialog, (Pred(j) * 2) + dTopEd, itmType, itmHdl, oldRect); { get button location }
- GetIText(itmHdl, theString);
- SetIText(itmHdl, theString);
- end;
- GetWTitle(theDialog, theString);
- SetWTitle(theDialog, 'Click and Drag or Press a Key to Cancel');
-
- { here's a nasty hack that changes the window type to a dBoxProc type so that the user will not }
- { cause MultiFinder to switch to another window if an open window from another application is }
- { clicked on (Note: Calling SetWTitle would cause the window to be redrawn as a dBoxProc window) }
- { the window type is restored to its original setting later... }
- { note: an alternate method would be to create a dBoxProc dialog beyond the edge of the screen }
- winKind := HiWord(Ord(DialogPeek(theDialog)^.window.windowDefProc));{ save window type for later restore }
- itmHdl := DialogPeek(theDialog)^.window.windowDefProc;
- IntPtr := @itmHdl;
- IntPtr^ := 256 * dBoxProc; { use dBoxProc to stop MF switching }
- DialogPeek(theDialog)^.window.windowDefProc := itmHdl; { actually set window type}
-
- { setup rect to use to gray title bar - bad idea since it may not work with alternate WDEFs...}
- titleRect := theDialog^.portRect;
- LocalToGlobal(titleRect.topLeft);
- LocalToGlobal(titleRect.botRight);
- OffsetRect(titleRect, 0, -18);
- titleRect.bottom := titleRect.top + 16;
-
- GetDItem(theDialog, dSetRectBtn, itmType, itmHdl, oldRect); { get button location }
- LocalToGlobal(oldRect.topLeft);
- LocalToGlobal(oldRect.botRight);
-
- New(deskPort);
- OpenPort(deskPort); { make grafport so can draw on screen }
- UnionRgn(GetGrayRgn, deskPort^.visRgn, deskPort^.visRgn); { add all monitors to visRgn of new grafPort }
-
- { here I remove the "Set" button from the clip region since I'll be changing its title and this }
- { eliminates the possibility of gray line artifacts left from using the notPatXOr drawing mode }
- { ...trust me... }
- rgnHdl := NewRgn;
- OpenRgn;
- FrameRoundRect(oldRect, 16, 16); { create button size region to remove from new grafPort }
- CloseRgn(rgnHdl);
- DiffRgn(deskPort^.clipRgn, rgnHdl, deskPort^.clipRgn); { remove button from clip region }
- DisposeRgn(rgnHdl);
-
- StuffHex(@marqueePat, '0F1E3C78F0E1C387');
- lastDraw := 0;
- oldRect := zVar.WinRect;
-
- PenMode(notPatXor); { allows easy redrawing of gray frames }
- SetCursor(CrossCurs^^); { bring up cross cursor }
- repeat
- if (TickCount > lastDraw + 1) then
- begin
- lastDraw := TickCount;
- for j := 0 to 7 do { set up blinking marquee pattern by shifting bits }
- rotateByte(@marqueePat[j]);
- FrameRect(oldRect); { erase old rect }
- PenPat(marqueePat);
- FrameRect(oldRect); { draw new rect }
- end;
- until GetNextEvent(mDownMask + keyDownMask, mouseEvent); { wait for mousedown }
- FrameRect(oldRect); { erase old rect }
- PenPat(gray);
-
- if mouseEvent.what = mouseDown then { key stroke allows rect to be unchanged }
- begin
- PenMode(patBic);
- PaintRect(titleRect); { gray title bar - bad idea since it may not work with alternate WDEFs...}
- PenMode(notPatXor); { allows easy redrawing of gray frames }
-
- SetRect(oldRect, 0, 0, 0, 0);
- zVar.WinRect := oldRect;
- startPt := mouseEvent.where; { globals are OK }
-
- while stilldown do { repeat until mouse button is released }
- begin
- GetMouse(endPt);
-
- if (endPt.h > startPt.h) and (endPt.v > startPt.v) then
- SetRect(zVar.WinRect, startPt.h, startPt.v, endPt.h, endPt.v)
- else if (endPt.h > startPt.h) and (endPt.v < startPt.v) then
- SetRect(zVar.WinRect, startPt.h, endPt.v, endPt.h, startPt.v)
- else if (endPt.h < startPt.h) and (endPt.v > startPt.v) then
- SetRect(zVar.WinRect, endPt.h, startPt.v, startPt.h, endPt.v)
- else
- SetRect(zVar.WinRect, endPt.h, endPt.v, startPt.h, startPt.v);
-
- if ShiftDown then { constrain rect to size of shortest side }
- with zVar.WinRect do
- begin
- height := bottom - top;
- width := right - left;
- if width > height then
- if startPt.h = left then { height < width }
- right := left + height
- else
- left := right - height
- else if startPt.v = top then { width < height }
- bottom := top + width
- else
- top := bottom - width
- end;
-
- if (zVar.WinRect.right - zVar.WinRect.left >= 150) and (zVar.WinRect.bottom - zVar.WinRect.top >= 100) then
- SetBtnTitle(theDialog, dSetRectBtn, 'OK') { change btn title to help user }
- else
- SetBtnTitle(theDialog, dSetRectBtn, 'Drag'); { change btn title to help user }
-
- if not EqualRect(oldRect, zVar.WinRect) then { update for new rect }
- begin
- FrameRect(oldRect); { erase old rect }
- PutRectVarInDialog; { update window rect display }
- FrameRect(zVar.WinRect); { draw current rect }
- oldRect := zVar.WinRect; { save current rect for later erasure }
- end;
- end;
- FrameRect(oldRect); { erase last rect }
- end;{ of mouseEvent.what = mouseDown }
-
- PenNormal;
- InitCursor; { restore arrow cursor }
- SetBtnTitle(theDialog, dSetRectBtn, 'Set'); { restore btn title }
- ClosePort(deskPort); { done with port - get rid of it }
- Dispose(deskPort);
- SetPort(theDialog); { be sure main window is current window }
-
- { restore window type to original value }
- { note: if a dBoxProc dialog was created beyond the edge of the screen, it should be disposed here }
- itmHdl := DialogPeek(theDialog)^.window.windowDefProc;
- IntPtr := @itmHdl;
- IntPtr^ := winKind;
- DialogPeek(theDialog)^.window.windowDefProc := itmHdl;
-
- SetWTitle(theDialog, theString);
- InvalRect(theDialog^.portRect);
- end; { of proc HandleSetRect }
-
-
- procedure DealwithDialogs (Event: EventRecord);
- var
- dlgPtr: DialogPtr;
- itemHit, j, itmType, winKind, totItems: Integer;
- err: OSErr;
- ItemWasHit, fix: Boolean;
- begin
- case Event.what of
- keydown, autokey:
- begin
- DealwithKeyDowns(Event);
- if ((Event.what = keydown) | (Event.what = autokey)) & (DialogSelect(Event, dlgPtr, ItemHit)) then
- ; { if Event was not altered by DealwithKeyDowns, pass key along to dialog manager }
- end;
- ActivateEvt:
- if GetWRefCon(WindowPtr(Event.message)) = AboutDemoID then
- DrawDefaultBtn(WindowPtr(Event.message), OK);
- UpdateEvt:
- begin
- {• ItemWasHit := DialogSelect(Event, dlgPtr, ItemHit);•}
- BeginUpdate(MainDlgPtr); { this method preserves the window's custom background color - if any }
- FixWindowColor(MainDlgPtr);
- DrawDialog(MainDlgPtr);
- EndUpdate(MainDlgPtr);
- DrawFreeRam;
- end;
- otherwise
- if DialogSelect(Event, dlgPtr, ItemHit) & (GetWRefCon(dlgPtr) = AboutDemoID) then
- begin
- SetPort(dlgPtr);
- case itemHit of
- OK:
- DemoAbout;
- Cancel:
- Finished := True;
- dSetRectBtn: { Set window rect }
- HandleSetRect(dlgPtr);
- dBoxWRad..dRDocWRad: { window types }
- begin
- ItemWasHit := ((itemHit = zVar.BoxType) & (TickCount - lastClick < GetDblTime));
- GetSetBtn(dlgPtr, zVar.BoxType, Off);
- fix := (zVar.BoxType <> itemHit);
- zVar.BoxType := itemHit;
- GetSetBtn(dlgPtr, zVar.BoxType, On);
- if fix then
- FixCloseCheckbox;
- if ItemWasHit then
- err := PostEvent(keyDown, enterKey);
- lastClick := TickCount;
- end;
- dMsgChk:
- begin
- zVar.Msg := not zVar.Msg;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.Msg));
- end;
- dCenterRad..dMainMonRad:
- begin
- ItemWasHit := ((itemHit - Succ(dCenterRad) = zVar.Center) & (TickCount - lastClick < GetDblTime));
- GetSetBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, Off); { set Center Window radio }
- zVar.Center := itemHit - Succ(dCenterRad);
- GetSetBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, On); { set Center Window radio }
- if ItemWasHit then
- err := PostEvent(keyDown, enterKey);
- lastClick := TickCount;
- end;
- dIconChk:
- begin
- zVar.ShowIcon := not zVar.ShowIcon;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.ShowIcon));
- end;
- dStylChk:
- begin
- zVar.Style := not zVar.Style;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.Style));
- end;
- dCopyChk:
- begin
- zVar.CopyIt := not zVar.CopyIt;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.CopyIt));
- end;
- dCloseChk:
- begin
- zVar.Close := not zVar.Close;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.Close));
- end;
- dEquivChk:
- begin
- zVar.Keys := not zVar.Keys;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.Keys));
- end;
- dModalChk:
- begin
- zVar.Modal := not zVar.Modal;
- GetSetBtn(dlgPtr, itemHit, Ord(zVar.Modal));
- end;
- dAboutBtn: { ? button }
- DoHelp;
- otherwise
- end;
- end;
- end;
- end; { of proc DealwithDialogs }
-
-
- procedure DealwithMouseDowns (Event: EventRecord);
- var
- j: SignedByte;
- WindowPointedTo, theWindow: WindowPtr;
- MouseLoc: Point;
- WindoLoc: integer;
- begin
- MouseLoc := Event.Where;
- WindoLoc := FindWindow(MouseLoc, WindowPointedTo);
- if IsAboutWindow(WindowPointedTo) then
- begin
- theWindow := WindowPointedTo; { save original window pointer }
- HandleAbout(WindowPointedTo, Event);
- if WindowPointedTo = nil then { About window was killed }
- for j := 1 to maxDemoWindows do { remove entry from window pointer array }
- if DemoWinPtr[j] = theWindow then
- begin
- DemoWinPtr[j] := nil;
- GetSetBtn(MainDlgPtr, OK, Off); { enable button }
- DrawDefaultBtn(MainDlgPtr, OK);
- end;
- end
- else
- begin
- case WindoLoc of
-
- inMenuBar:
- ;
-
- inSysWindow:
- ;
-
- inContent:
- if WindowPointedTo <> FrontWindow then
- begin
- SelectWindow(WindowPointedTo); { bring to front }
- while WindowPointedTo <> nil do
- begin
- HandleAbout(WindowPointedTo, Event); { pass event to About Unit }
- WindowPointedTo := WindowPtr(WindowPeek(WindowPointedTo)^.nextWindow);
- end;
- end
- else
- begin {do something}
- sysbeep(1);
- end;
-
- inGrow:
- ;
-
- InDrag: { click in drag bar }
- begin
- DragWindow(WindowPointedTo, MouseLoc, ScreenBits.bounds);
- end;
-
- inGoAway:
- if TrackGoAway(WindowPointedTo, MouseLoc) then
- DisposeWindow(WindowPointedTo); {since W mgr allocated space}
-
- otherwise
- end;{ of case}
- end;
- end; { of proc DealwithMouseDowns }
-
-
- procedure DealwithActivates (Event: EventRecord);
- var
- TargetWindow: WindowPtr;
- begin
- TargetWindow := WindowPtr(Event.message);
-
- if IsAboutWindow(TargetWindow) then
- HandleAbout(TargetWindow, Event)
- else
- begin
- if Odd(Event.modifiers) then {then the window is becoming active}
- begin
- SetPort(TargetWindow);
- {and activate whatever else you need}
- {the scroll bars}
- {hilite selected text}
- end
- else
- begin
- {deactivate whatever you need}
- {deactivate the scroll bars}
- {UNhilite selected text}
- end;
- end;
- end; { of proc DealwithActivates }
-
-
- procedure DealwithUpdates (Event: EventRecord);
- var
- UpDateWindow: WindowPtr;
- begin
- UpdateWindow := WindowPtr(Event.message);
- if IsAboutWindow(UpdateWindow) then
- HandleAbout(UpdateWindow, Event)
- else
- begin
- SetPort(UpdateWindow); {set the port to one in Evt.msg}
- BeginUpDate(UpdateWindow);
- DrawDialog(UpdateWindow);
- EndUpDate(UpdateWindow);
- end;
- end; { of proc DealwithUpdates }
-
-
- procedure MainEventLoop;
- var
- Event: EventRecord;
- ProcessIt: Boolean;
- NextWinPeek, WinPeek: WindowPeek;
- begin
- repeat
- PurgeMem(ramDemand);
- if (ramFree <> FreeMem) then
- begin
- SetPort(MainDlgPtr);
- InvalRect(ramRect);
- end;
-
- SystemTask; {so you can support Desk Accessories}
- ProcessIt := GetNextEvent(EveryEvent, Event);
-
- if IsDialogEvent(Event) then
- DealwithDialogs(Event)
- else if ProcessIt then{is true}
- case Event.what of
-
- mouseDown:
- DealwithMouseDowns(Event);
- keydown, autokey:
- DealwithKeyDowns(Event);
- ActivateEvt:
- DealwithActivates(Event);
- UpDateEvt:
- DealwithUpdates(Event);
-
- otherwise
- end;{of Case}
- until Finished; {terminate the program}
-
-
- { destroy any open About windows… }
- WinPeek := WindowPeek(FrontWindow);
- while WinPeek <> nil do
- begin
- NextWinPeek := WinPeek^.nextWindow; { if it's window is an About window, it's history - save next window pointer }
- if IsAboutWindow(WindowPtr(WinPeek)) then { is it an About window? }
- begin
- CloseAbout(WindowPtr(WinPeek)); { then kill it…}
- DrawFreeRam;
- end;
- WinPeek := NextWinPeek;
- end;
-
- { finally, destroy main dialog }
- DisposDialog(MainDlgPtr);
- end; { of proc MainEventLoop }
-
-
- function OpenColorDlg (dlgID: Integer): DialogPtr;
- { open regular B&W or color dialog - allows for accurate display of custom content color }
- var
- hasColor: Boolean;
- theWorld: SysEnvRec;
- dlgPtr: DialogPtr;
- aRect: Rect;
- DITLhndl: Handle;
- WinTitle: Str255;
- procID: Integer;
- begin
- if (SysEnvirons(1, theWorld) <> envNotPresent) then { SysEnvirons call is available }
- hasColor := theWorld.hasColorQD { has Color QuickDraw }
- else
- hasColor := False;
-
- if hasColor then
- begin
- dlgPtr := getNewDialog(dlgID, nil, Pointer(-1)); { get dialog box }
- aRect := dlgPtr^.portRect;
- GetWTitle(dlgPtr, WinTitle);
- procID := GetWVariant(dlgPtr); { GetWVariant func requires MacPlus or better }
- DisposDialog(dlgPtr);
-
- DITLhndl := Get1Resource('DITL', dlgID);
- dlgPtr := NewCDialog(nil, aRect, WinTitle, False, procID, WindowPtr(nil), False, 0, DITLhndl);
- end
- else
- dlgPtr := getNewDialog(dlgID, nil, Pointer(-1)); { get B&W dialog box }
-
- OpenColorDlg := dlgPtr;
- end; { of func OpenColorDlg }
-
-
- procedure Initialize;
- var
- j: SignedByte;
- aRect: Rect;
- begin
- CrossCurs := GetCursor(crosscursor); { read in from system resource }
- HLock(Handle(CrossCurs)); { lock the handle down }
-
- MainDlgPtr := OpenColorDlg(AboutDemoID);
- SetWRefCon(MainDlgPtr, AboutDemoID); { store ID for use in distinguishing window later… }
-
- { let Dialog Manager draw RoundRect around default btn }
- SetRect(aRect, 0, 0, 0, 0);
- SetDItem(MainDlgPtr, 3, userItem, @DrawDefaultBtn, aRect);
-
- for j := 1 to maxDemoWindows do
- DemoWinPtr[j] := nil;
-
- Finished := False;
- zVar.BoxType := dBoxWRad;
- zVar.Center := AboutNoCenter;
- zVar.Msg := True;
- zVar.ShowIcon := True;
- zVar.Style := True;
- zVar.CopyIt := True;
- zVar.Close := True;
- zVar.Keys := True;
- zVar.Modal := False;
- zVar.MsgText := Concat(AboutVersion, ' Unit', chr(13), CopyrightMsg);
- zVar.TitleText := Concat(AboutVersion, ' Demo');
- SetRect(zVar.WinRect, 22, 42, 456, 303); { set default window rect }
-
- PutVarsInDialog; { put window rect values into edit text boxes }
- FixCloseCheckbox;
- CenterWindow(MainDlgPtr, True); { center,display,set port,default btn }
-
- lastClick := TickCount;
- SetRect(ramRect, 1, 0, 120, 10);
- ramFree := 0;
- ramDemand := maxint * 10;
- InitCursor;
- end; { of proc Initialize }
-
-
- {main program loop}
-
- begin
- Initialize;
- MainEventLoop;
- end.